package generator

import (
	"os"
	"text/template"
	"time"
)

// createDocFile 生成Doc文件
func (g *Generator) createDocFile() error {
	// g.Info.CreateImplementFilePath(rf.Name)
	dest := g.Info.CreateImplementFilePath("doc.go")
	tmpl, err := template.ParseFS(templates, "resources/doc.tpl") // .Parse(interfacego)
	// tmpl, err := template.New("interface").Parse(interfacego)
	if err != nil {
		return err
	}

	file, err := os.OpenFile(dest, os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
	if err != nil {
		return err
	}
	defer file.Close()

	return tmpl.Execute(file, map[string]interface{}{
		"Time":        time.Now().Format("2006-01-02 15:04:05"),
		"packageName": g.Info.Dialect,
	})
}
